package com.spider.utils;

import java.net.URL;

import org.jdiy.core.Dao;
import org.jdiy.core.JDiyContext;
import org.jdiy.util.Fs;

public class CommonUtil {


	private static JDiyContext context;
	public static JDiyContext getJDiyContext() throws Exception{
		if(context == null){
			 //下面的URL对象用于指定jdiy.xml配置文件的位置（相对于class目录）:  
	        URL xmlLocation = Fs.getResource("jdiy.xml");  
	        //指定您的应用程序根路径地址(APP_ROOT),也可以直接写绝对路径,例如:"e:\\myjava\\jdiy-test"  
	        String rootPath = Fs.getResource("../").toString();   
	        //创建一个JDiy上下文对象:   
			context = JDiyContext.newInstance(xmlLocation, rootPath);
		}
		return context;
	}
	private static Dao dao;
	public static Dao getDao() throws Exception{
		if(dao == null){
			dao = getJDiyContext().getDao();
		}
		return dao;
	}
}
